package zhtt.action05_interceptor;


import javax.servlet.http.HttpServletRequest;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
import org.apache.struts2.ServletActionContext;

public class DigitCertificateCheck implements Interceptor {

	private String authority_flag;

	public String intercept(ActionInvocation invocation) throws Exception {
		System.out.println("authority_flag:"+authority_flag);
		String result = invocation.invoke();
		HttpServletRequest request = ServletActionContext.getRequest();
		if(request.getServletPath().indexOf("login.action")==-1){
			User loginUser=(User)ActionContext.getContext().getSession().get("loginUser");
			if(loginUser!=null){
				String isSinglePointLogin=(String) ActionContext.getContext().getSession().get("isSinglePointLogin");
				if("true".equals(isSinglePointLogin)){
					ActionContext.getContext().getSession().put("digitcertificatecheckinfo", "未插数字证书");
					ActionContext.getContext().getSession().clear();
					invocation.setResultCode("login");
					result = invocation.invoke();
				}
			}
		}
		return result;
	}

	public void destroy() {
	}

	public void init() {
	}

	public void setAuthority_flag(String authority_flag) {
		this.authority_flag = authority_flag;
	}
}